package com.teemor.im.remoting.instance;

import com.teemor.im.common.command.RemoteCommand;
import com.teemor.im.discovery.node.ServerNode;
import com.teemor.im.remoting.ReqCallback;
import com.teemor.im.remoting.exception.RemotingConnectClosedException;
import io.netty.channel.ChannelFuture;

/**
 * 远程服务接口
 *
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/6/12 13:30
 */
public interface RemotingService {

    void start();

    void stop();

    void restart();

    boolean isActive();

    /**
     * 执行请求
     *
     * @param request
     * @param node
     * @return
     * @throws RemotingConnectClosedException
     */
    ChannelFuture invokeRequest(RemoteCommand request, ServerNode node) throws RemotingConnectClosedException;

    /**
     * 同步发送消息
     *
     * @param request 请求信息
     * @param target  目标节点
     * @return response
     */
    RemoteCommand syncSend(RemoteCommand request, ServerNode target, long timeoutMillis) throws InterruptedException, RemotingConnectClosedException;

    /**
     * 异步发送消息
     *
     * @param request  请求信息
     * @param target   目标节点
     * @param callback 回调接口
     */
    void asyncSend(RemoteCommand request, ServerNode target, ReqCallback callback, long timeoutMillis) throws InterruptedException;

    /**
     * 单向发送，不需要响应
     *
     * @param request 请求信息
     * @param target  目标节点
     */
    void oneWaySend(RemoteCommand request, ServerNode target, long timeoutMillis) throws InterruptedException;


}
